package com.tyqx.hashchainbiz.controller;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.tyqx.hashchainbean.vo.MongoDbUserPathVO;
import com.tyqx.hashchainbiz.service.QueryDonateService;
import com.tyqx.hashchainutil.common.CryptoUtil;
import com.tyqx.hashchainutil.org.app.util.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.nio.file.Path;
import java.util.List;
import java.util.Map;

import static com.mongodb.client.model.Filters.eq;

@RestController
@CrossOrigin
public class TestController {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Resource
    private QueryDonateService queryDonateService;


    @RequestMapping(value = "/save", method = RequestMethod.GET)
    public void save() {
        try {
            //mongoTemplate.save(myTestList.get(0),"myTest");  //向MongoDB里面插入数据
            boolean flag=mongoTemplate.exists(new Query(),"merkleRoot");
            System.out.println(flag);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) throws Exception {
        String testString = "aaa";
        CryptoUtil cryptoUtil = new CryptoUtil();
        String caType = "msp";
        Long orgIndex = 0L;
        String userName = "jzyc";
        Path keyPath = (Path) Util.readUserContext(caType, userName, orgIndex).get("clientKeyPath");
        String testSign = cryptoUtil.sign(keyPath, testString);
        Map<String, Object> pathMap = Util.readUserContext(caType, userName, orgIndex);
        Path clientCertPath = (Path) pathMap.get("clientCertPath");
        boolean flag = cryptoUtil.verify(clientCertPath, testSign, testString);
        System.out.println("123");
    }


}
